import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [{
  path: '/login',
  component: () => import('@/views/login/index'),
  hidden: true
},

{
  path: '/404',
  component: () => import('@/views/404'),
  hidden: true
},

{
  path: 'cs',
  component: Layout,
  // redirect: '/shiTiLei/manage',
  redirect: '/dashboard',
  children: [{
    path: 'dashboard',
    name: 'Dashboard',
    component: () => import('@/views/dashboard/index'),
    meta: {
      title: 'Dashboard',
      icon: 'dashboard'
    }
  }]
},
// 自己新增路由

{
  path: '/',
  component: Layout,
  redirect: 'index',
  name: 'shouye',
  children: [{
    path: 'index',
    name: 'Index',
    component: () => import('@/views/rfcwgl/index/index'),
    meta: {
      title: '首页',
      icon: 'index'
    }
  }]
},
// 报销
{
  path: '/baoXiao',
  component: Layout,
  name: 'baoXiao',
  redirect: 'chaiLvFei',
  // alwaysShow: true,
  meta: {
    title: '报销',
    icon: 'baoxiao'
  },
  children: [{
    path: 'chaiLvFei',
    name: 'chaiLvFBX',
    component: () =>
      import('@/views/rfcwgl/chaiLvFBX/manage/chaiLvFBXManage/index.vue'),
    meta: {
      title: '差旅费报销',
      icon: 'chailvfei'
    }
  },
  {
    path: 'feiYongBX',
    name: 'feiYongBaoXiao',
    component: () =>
      import('@/views/rfcwgl/feiYongBX/manage/feiYongBFManage/index.vue'),
    meta: {
      title: '费用报销',
      icon: 'feiyongbaoxiao'
    }
  },
  {
    path: 'feiYongJH',
    name: 'feiYongJiHua',
    component: () =>
      import('@/views/rfcwgl/feiYongJH/manage/feiYongJHManage/index.vue'),
    meta: {
      title: '费用计划',
      icon: 'feiyongjihua'
    }
  },
  {
    path: 'chuChaiBZBZ',
    name: 'chuChaiBuZhuBiaoZhun',
    component: () =>
      import(
        '@/views/rfcwgl/chuChaiBZBZ/manage/chuChaiBZBZManage/index.vue'
      ),
    meta: {
      title: '出差补助标准',
      icon: 'buzhu'
    }
  },
  {
    path: 'faPiaoGL',
    name: 'fapiaoguanli',
    component: () =>
      import('@/views/rfcwgl/faPiaoGL/manage/faPiaoGLManage/index.vue'),
    meta: {
      title: '发票管理',
      icon: 'fapiaoguanli'
    }
  }
  ]
},
// 借款
{
  path: '/jiekuan',
  component: Layout,
  redirect: 'loan',
  name: 'jiekuan',
  // alwaysShow: true,
  meta: {
    title: '借还款管理',
    icon: 'jiehuankuan'
  },
  children: [{
    path: 'loan',
    name: 'loan',
    component: () =>
      import('@/views/rfcwgl/jieKuan/manage/jieKuanManage/index.vue'),
    meta: {
      title: '借款',
      icon: 'jiekuan'
    }
  },
  {
    path: 'repayment',
    name: 'repayment',
    component: () =>
      import('@/views/rfcwgl/huanKuan/manage/huanKuanManage/index.vue'),
    meta: {
      title: '还款',
      icon: 'huankuan'
    }
  },
  {
    path: 'Setting',
    name: 'Setting',
    component: () =>
      import(
        '@/views/rfcwgl/jieKuanBZSD/manage/jieKuanBZSDManage/index.vue'
      ),
    meta: {
      title: '借款标准设定',
      icon: 'jiekuanbiaozhun'
    }
  }
  ]
},
// 字典表
{
  path: '/dictionary',
  component: Layout,
  name: 'ziDianBiao',
  // alwaysShow: true,
  // meta: { title: '借还款管理', , icon: 'form' },
  children: [{
    path: 'Manage',
    name: 'Manage',
    component: () =>
      import('@/views/rfcwgl/ziDianB/manage/ziDianBManage/index.vue'),
    meta: {
      title: '字典表管理',
      icon: 'zidian'
    }
  }]
},
{
  path: '/shiTiLei',
  component: Layout,
  redirect: '/shiTiLei/manage',
  name: 'shiTiLei',
  alwaysShow: true,
  meta: {
    title: '实体类管理',
    icon: ''
  },
  children: [{
    path: 'manage',
    name: 'manage',
    component: () => import('@/views/app-dev/shiTiLei/manage/shiTiLManage/index.vue'),
    meta: {
      title: '实体类',
      icon: ''
    },
    children: [{
      path: 'shiTiLei/Show',
      name: 'showRecord',
      hidden: true,
      component: () => import('@/views/app-dev/shiTiLei/show/shitiLShow/index.vue')
    }]
  }]
},
]

/**
 * asyncRoutes
 * the routes that need to be dynamically loaded based on user roles
 */
export const asyncRoutes = [

  {
    path: 'external-link',
    component: Layout,
    children: [{
      path: 'https://panjiachen.github.io/vue-element-admin-site/#/',
      meta: {
        title: 'External Link',
        icon: 'link'
      }
    }]
  },

  // 404 page must be placed at the end !!!
  {
    path: '*',
    redirect: '/404',
    hidden: true
  }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({
    y: 0
  }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
